const QQMapWX = require('../../../libs/qqmap-wx-jssdk.min.js');
const app = getApp();
var qqmapsdk;
Page({ 
    data: { 
      markers:[],
      enableSatellite: false,
      typeShow: '1',
      searchName: ''
    },
    onLoad: function() {
      qqmapsdk = new QQMapWX({
        key: 'RKEBZ-5AHRG-UESQB-ITOOU-5WSYJ-T4FCQ'
      });
    },
    onEnableSatellite: function(e){
      var id = e.currentTarget.id
      var show =false
      if(id == '1'){
        show = false
      }else if(id == '2'){
        show = true
      }
      this.setData({
        enableSatellite: show,
        typeShow: id
      })
      
    },
    updateValue(e) {
      this.setData({
        searchName: e.detail.value
      })
    },
    nearby_search:function(){
      var _this = this;
      // 调用接口
      qqmapsdk.search({
         keyword: this.data.searchName,  //搜索关键词
         location: '30.477044,114.410642',  //设置周边搜索中心点
         success: function (res) { //搜索成功后的回调
           var mks = []
           for (var i = 0; i < res.data.length; i++) {
             mks.push({ // 获取返回结果，放到mks数组中
               title: res.data[i].title,
               id: res.data[i].id,
               latitude: res.data[i].location.lat,
               longitude: res.data[i].location.lng,
               iconPath: "/images/map/marker_red.png", //图标路径
               width: 20,
               height: 20
             })
           }
           _this.setData({ //设置markers属性，将搜索结果显示在地图中
             markers: mks
           })
         },
         fail: function (res) {
           console.log(res);
         },
         complete: function (res){
           console.log(res);
         }
     });
   }
})